<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ include file="/common/includes.jsp" %>
<html xmlns="http://www.w3.org/1999/xhtml">
  <head>
    <title>成品物料管理编辑</title>
	<!-- import css and js --> 
	<%@ include file="/common/metaInput.jsp" %>  
	<script src="${ctx}/js/jsp/comm.js" type="text/javascript"></script>
<script type="text/javascript">
var basic_Url="${ctx}/yd/basic/materialsEndProduct";
$(function(){
$("#inputForm").validate({			   
	onsubmit: true,
	 /*执行ajaxsubmit  */ 
    submitHandler: function(editform) {
            
        //alert(jsonInfo); 
        try{			    		
            url =  basic_Url+"/save.do";
            var api = frameElement.api;
        	var W = api.opener;
            getReturnMessage(url,"inputForm",W.searchAP);
            W.pid='${pid}';
        }catch(e){alert(e)}
    }
 }
);

if ('${flag}' == 'edit'){
	 $("#code").attr("disabled","disabled");
	 $("select[id='placeCode']").attr("disabled","disabled");
	 $("input[id='materialTypeCode']").attr("disabled","disabled");
	 $("input[id='materialNumberCategoryCode']").attr("disabled","disabled");
	 $("select[id='supplierCode']").attr("disabled","disabled");
	 $("input[id='unit']").attr("disabled","disabled");
}

if('${flag}' == 'browse'){
	$("input[type!='hidden']").attr("disabled","disabled");
	$("select").attr("disabled","disabled");//禁用SELECT标签
	$("textarea").attr("disabled","disabled");//禁用TEXTAREA标签
}
 
})
function submitForm(param){
    //设置ajax全局同步
	var flag=true;
	var zs =/^[0-9]{0}([0-9])+$/;
	if($("#lotaStandardqty").val() == ""){
		$("#lotaStandardqtySpan").text("不能为空");
		flag=false;
	}else if(!zs.test($("#lotaStandardqty").val()) || parseInt($("#lotaStandardqty").val())<1){
		$("#lotaStandardqtySpan").text("只能输入大于0的整数");
		flag=false;
	}
	if($("#lotbStandardqty").val() == ""){
		$("#lotbStandardqtySpan").text("不能为空");
		flag=false;
	}else if(!zs.test($("#lotbStandardqty").val()) || parseInt($("#lotbStandardqty").val())<1){
		$("#lotbStandardqtySpan").text("只能输入大于0的整数");
		flag=false;
	}
	if($("#lotcStandardqty").val() == ""){
		$("#lotcStandardqtySpan").text("不能为空");
		flag=false;
	}else if(!zs.test($("#lotcStandardqty").val()) || parseInt($("#lotcStandardqty").val())<1){
		$("#lotcStandardqtySpan").text("只能输入大于0的整数");
		flag=false;
	}
	if($("#ldfRows").val() != null  &&  $("#ldfRows").val().length>0){
		if(!zs.test($("#ldfRows").val()) || parseInt($("#ldfRows").val())<1){
			$("#ldfRowsSpan").text("只能输入大于0的整数");
			flag=false;
		}
	}
	
	if(flag){
		jQuery.ajaxSettings.async = false;
	  	$("#submitFlag").val(param);
	    $("#inputForm").submit();
	}
	
 }		
	
function yz(str){
	var number =/^[0-9]{0}([0-9])+$/;
	var vl = $("#"+str).val();
	if(vl != null && vl.length > 0){
		if(!number.test(vl) || parseInt(vl)<1){
			if($("#"+str+"Span").text() == null || $("#"+str+"Span").text().length <= 0){
				$("#"+str+"Span").text("只能输入大于0的整数");
				return false;
			}
		}else{
			if($("#"+str+"Span").text() != null || $("#"+str+"Span").text().length > 0){
				$("#"+str+"Span").text("");
			}
			
		}
	}	
}

function updateDescription(){
	 var customerId =$("#customerId").val();
	 var packageType = $("#packageType").val();
	 var spec = $("#spec").val();
	 var waferVersion =$("#waferVersion").val();
	 var str = "";
	 if(customerId!= null && customerId.length>0){
		 str +=customerId;
	 }
	if(packageType!= null && packageType.length>0){
		if(customerId!= null && customerId.length>0){
			str +=";"+packageType; 
		 }else{
			 str +=packageType; 
		 }
		
	}
	if(spec!= null && spec.length>0){
		if((customerId!= null && customerId.length>0)||(packageType!= null && packageType.length>0)){
			str +=";"+spec; 
		 }else{
			 str +=spec; 
		 }
	}
	if(waferVersion!= null && waferVersion.length>0){
		if((customerId!= null && customerId.length>0)||(packageType!= null && packageType.length>0)||(spec!= null && spec.length>0)){
			str +=";"+waferVersion; 
		 }else{
			 str +=waferVersion; 
		 }
	}
	$("#description").val(str);
}
</script>

</head>

<body>

<form id="inputForm" action="" method="post">
<input type="hidden" id="id" name="id" value="${materials.id}"/>
<!-- 用于标识提交按钮 -->
<input type="hidden" id="submitFlag" value="" />
 <div class="pageContent" >
    <div class="panel">
         <table class="TableBlock" align="center">
          			<tr>
          				<td nowrap>成品物料名称:</td>
          				<c:choose>
	   		                 <c:when test="${not empty materials.code}">
	   		                 <td>
	   		                		<input type="text" id="name" name="name" class="inp_width_98p required" readonly="readonly" value="${materials.name == null ? pname : materials.name}" />
	   		                 </td>
	   		            	<td nowrap>成品物料编码:</td>
	   		                 <td>
	   		                		<input type="text" id="code" name="code" class="inp_width_98p required" value="${materials.code}" />
	   		                 </td>   
	   		             	</c:when>  
	   		             	<c:otherwise>
	   		             	<td colspan="3">
	   		                		<input type="text" id="name" name="name" class="inp_width_98p required" readonly="readonly"  value="${materials.name == null ? pname : materials.name}" />
	   		                 </td>
	   		                 </c:otherwise>
	   		          </c:choose>
   		           </tr>
   		           <tr>
                    	 <td nowrap>所属类型:</td>
   		                 <td>
   		                		<input type="text" disabled="disabled" class="inp_width_98p" value="${pname}" />
   		                		<input type="hidden" id="pid" name="pid"  value="${pid}" />
   		                		<input type="hidden" id="pname" name="pname"  value="${pname}" />
   		                 </td>
   		                 
   		                  <td nowrap>单价:</td>
   		                 <td>
   		                		<input type="text" id="price"  class="inp_width_98p required"  name="price" value="${materials.price}" />
   		                 </td>
   		           </tr>
   		             <tr>
   		                 <td nowrap>型号:</td>
   		                 <td>
   		                		<input type="text" id="spec" name="spec" class="inp_width_98p required" value="${materials.spec}"  onkeyup="updateDescription()"/>
   		                 </td>
   		                 
   		                 <td nowrap>客户简码:</td>
   		                 <td>
   		                 		<input type="text" id="customerId" name="customerId" class="inp_width_98p required" value="${materials.customerId}"   onkeyup="updateDescription()"/>
   		                 </td>
   		           </tr>
   		           <tr>
   		                 <td nowrap>封装类型:</td>
   		                 <td>
   		                		<input type="text" id="packageType" name="packageType" class="inp_width_98p required" value="${materials.packageType}"   onkeyup="updateDescription()"/>
   		                 </td>
   		                 
   		                 <td nowrap>条件票:</td>
   		                 <td>
   		                		<input type="text" id="planId" name="planId" class="inp_width_98p" value="${materials.planId}" />
   		                 </td>
   		           </tr>
   		            <tr>
   		                <td nowrap>默认仓库:</td>
   		                 <td>
   		                 <select id="defaultWarehouse" name="defaultWarehouse" class="inp_width_98p">
   		                 	<option></option>
   		                 	<c:forEach items="${bStorageinfoDOs }" var="bd">
   		                 		<option value="${bd.name }">${bd.name }</option>
   		                 	</c:forEach>
   		                 </select>
   		                 <script type="text/javascript">
   		                 	$("#defaultWarehouse").val('${materials.defaultWarehouse}');
   		                 </script>
   		                 </td>
   		                 
   		                 <td nowrap>产品型号版本:</td>
   		                 <td>
   		                		<input type="text" id="waferVersion" name="waferVersion"  class="inp_width_98p required" value="${materials.waferVersion}"   onkeyup="updateDescription()"/>
   		                 </td>
   		           </tr>
   		           <tr>
   		                 <td nowrap>线径:</td>
   		                 <td>
   		                		<input type="text" id="wire" name="wire"  class="inp_width_98p" value="${materials.wire}" />
   		                 </td>
   		                 
   		                 <td nowrap>导线架排数:</td>
   		                 <td>
   		                		<input type="text" id="ldfRows" name="ldfRows" class="inp_width_98p" value="${materials.ldfRows}" onkeyup="yz('ldfRows')"/>
   		                		<span id='ldfRowsSpan' style='color: red'></span>
   		                 </td>
   		           </tr>
   		           
   		            <tr>
   		                 <td nowrap>除胶方式:</td>
   		                 <td>
   		                		<input type="text" id="deflashType" name="deflashType" class="inp_width_98p" value="${materials.deflashType}" />
   		                 </td>
   		                 
   		                 <td nowrap>重工标记:</td>
   		                 <td>
   		                		<select id="rework" name="rework"  class="inp_width_98p required">
   		                 			<option></option>
   		                 			<option value="Y">Y</option>
   		                 			<option value="N">N</option>
   		                 		</select>
   		                 		<script type="text/javascript">
   		                 			$("#rework").val('${materials.rework}');
   		                 		</script>
   		                 </td>
   		           </tr>
   		           
   		           
   		            <tr>
   		                 <td nowrap>工程标记:</td>
   		                 <td>
   		                 		<select id="engFlag" name="engFlag"  class="inp_width_98p required">
   		                 			<option></option>
   		                 			<option value="Y">Y</option>
   		                 			<option value="N">N</option>
   		                 		</select>
   		                 		<script type="text/javascript">
   		                 			$("#engFlag").val('${materials.engFlag}');
   		                 		</script>
   		                 </td>
   		                 
   		                 <td nowrap>海关品名:</td>
   		                 <td>
   		                		<input type="text" id="customId" name="customId" class="inp_width_98p" value="${materials.customId}" />
   		                 </td>
   		           </tr>
   		           
   		           
   		           <tr>
   		                 <td nowrap>封装规范:</td>
   		                 <td>
   		                		<input type="text" id="bondingDirgarm" name="bondingDirgarm"  class="inp_width_98p required"  value="${materials.bondingDirgarm}" />
   		                 </td>
   		                 
   		                 <td nowrap>描述:</td>
   		                 <td>
   		                		<input type="text" id="description" name="description" class="inp_width_98p"readonly="readonly"  value="${materials.description}" />
   		                 </td>
   		           </tr>
   		           
   		           
   		           <tr>
   		                 <td nowrap>LotA标准数:</td>
   		                 <td>
   		                		<input type="text" id="lotaStandardqty" name="lotaStandardqty"  class="inp_width_98p" value="${materials.lotaStandardqty}" onkeyup="yz('lotaStandardqty')" />
   		                 		<span id='l1' style='color: red'>*</span>
   		                 		<span id='lotaStandardqtySpan' style='color: red'></span>
   		                 </td>
   		                 
   		                 <td nowrap>LotB标准数:</td>
   		                 <td>
   		                		<input type="text" id="lotbStandardqty" name="lotbStandardqty" class="inp_width_98p" value="${materials.lotbStandardqty}" onkeyup="yz('lotbStandardqty')" />
   		                		<span id='l2' style='color: red'>*</span>
   		                		<span id='lotbStandardqtySpan' style='color: red'></span>
   		                 </td>
   		           </tr>
   		           
   		           
   		           <tr>
   		                 <td nowrap>LotC标准数:</td>
   		                 <td>
   		                		<input type="text" id="lotcStandardqty" name="lotcStandardqty" class="inp_width_98p" value="${materials.lotcStandardqty}" onkeyup="yz('lotcStandardqty')" />
   		                		<span id='l3' style='color: red'>*</span>
   		                		<span id='lotcStandardqtySpan' style='color: red'></span>
   		                 </td>
   		                 
   		                 <td nowrap>测试规范:</td>
   		                 <td>
   		                		<input type="text" id="fileNo" name="fileNo" class="inp_width_98p" value="${materials.fileNo}" />
   		                 </td>
   		           </tr>
   		           
   		           
   		           <tr>
   		                 <td nowrap>测试程式名:</td>
   		                 <td>
   		                		<input type="text" id="testperograme" name="testperograme" class="inp_width_98p" value="${materials.testperograme}" />
   		                 </td>
   		                 
   		                 <td nowrap>生效:</td>
   		                 <td>
   		                 		<select id="activity" name="activity"  class="inp_width_98p required">
   		                 			<option></option>
   		                 			<option value="Y">Y</option>
   		                 			<option value="N">N</option>
   		                 		</select>
   		                 		<script type="text/javascript">
   		                 			$("#activity").val('${materials.activity}');
   		                 		</script>
   		                 </td>
   		           </tr>
   		           
   		            <tr>
   		                 <td nowrap>地点代码:</td>
   		                 <td>
   		                 	<select id="placeCode" name="placeCode"  class="inp_width_98p required">
   		                 		<option></option>
   		                 		<c:forEach items="${areaDOs }" var="areaDOs">
   		                 			<option value="${areaDOs.areacode }">${areaDOs.areaname }</option>
   		                 		</c:forEach>
   		                 	</select>
   		                 	<script type="text/javascript">
								$("#placeCode").val('${materials.placeCode}');
							</script>
   		                 </td>
   		                 
   		                 <td nowrap>物料类型代码:</td>
   		                 <td>
   		                <c:choose>
   		                 	<c:when test="${not empty materials.materialTypeCode}">
   		                 		<input type="hidden" id="materialTypeCode" class="inp_width_98p required"  name="materialTypeCode"  value="${materials.materialTypeCode}" />
   		                 		<input type="text" id="materialTypeCodeName" class="inp_width_98p required" readonly="readonly" name="materialTypeCodeName"  value="${materials.materialTypeCodeName}" />
   		                 	</c:when>
   		                 	<c:otherwise>
   		                 		<input type="hidden" id="materialTypeCode" class="inp_width_98p required" name="materialTypeCode"  value="${wlTypeRemark.remark}" />
   		                 		<input type="text" id="materialTypeCodeName" class="inp_width_98p required" readonly="readonly"  name="materialTypeCodeName"  value="${wlTypeRemark.name}" />
   		                 	</c:otherwise>
   		                </c:choose>	
   		                 </td>
   		           </tr>
   		           <tr>
   		                 <td nowrap>料号类别代码:</td>
   		                 <td>
   		                <c:choose>
   		                 <c:when test="${not empty materials.materialTypeCode}">
   		                 		<input type="hidden" id="materialNumberCategoryCode" class="inp_width_98p required"  name="materialNumberCategoryCode"  value="${materials.materialNumberCategoryCode}" />
   		                 		<input type="text" id="materialNumberCategoryCodeName" class="inp_width_98p required" readonly="readonly"  name="materialNumberCategoryCodeName"  value="${materials.materialNumberCategoryCodeName}" />
   		                 	</c:when>
   		                 	<c:otherwise>
   		                 		<input type="hidden" id="materialNumberCategoryCode" class="inp_width_98p required"  name="materialNumberCategoryCode"  value="${lhTypeRemark.remark}" />
   		                 		<input type="text" id="materialNumberCategoryCodeName" class="inp_width_98p required" readonly="readonly"  name="materialNumberCategoryCodeName"  value="${lhTypeRemark.name}" />
   		                 	</c:otherwise>
   		                </c:choose>
   		                 </td>
   		                 
   		                 <td nowrap>供应商代码:</td>
   		                 <td>
	   		                 		<select id="supplierCode" name="supplierCode" class="inp_width_98p required">
	   		                 		<option></option>
	   		                 		<c:forEach items="${companyDOs }" var="companyDOs">
	   		                 			<option value="${companyDOs.code }">${companyDOs.code }-${companyDOs.name }</option>
	   		                 		</c:forEach>
	   		                 	</select>
	   		                 	<script type="text/javascript">
									$("#supplierCode").val('${materials.supplierCode}');
								</script>
   		                 </td>
   		           </tr>
   		           
   		           <tr>
   		             <td>基本单位:</td>
   		             <!-- 添加基本单位默认值 @modify by huang.xuming [2013-09-10] -->
   		           	 <%-- <td><input id="unit" style="width: 40%;" name="unit" value="${not empty materials.unit ? materials.unit :'PCS'}" class="required"/></td> --%>
   		             <td>
   		             <c:choose>
   		             <c:when test="${empty materials.unit }">
                 		<select id="unit" name="unit" class="inp_width_98p required" >
	                 		<option ></option>
	                 		<c:forEach items="${unitDOs }" var="unitDOs">
	                 		<!-- 修改基本单位默认设置为PCS @modify by he.fangzhou [2013-11-14] -->	                 			
	                 			<c:choose>
			                    <c:when test="${unitDOs.unitname=='PCS'}">
			                       <option selected="selected" value="<c:out value="${unitDOs.unitname }"/>"> 
			                             <c:out value="${unitDOs.unitname }"/>
			                       </option>
			                    </c:when>
			                    <c:otherwise>
			                        <option  value="<c:out value="${unitDOs.unitname }"/>"> 
			                           <c:out value="${unitDOs.unitname }"/>
			                        </option>
			                    </c:otherwise>
                  				</c:choose>
	                 		</c:forEach>
 		                </select>
				    	</c:when>
				    	<c:otherwise>
				    	<input id="unit" class="inp_width_98p" name="unit" value="${materials.unit}" readonly="readonly"/>
				    	</c:otherwise>
				    	</c:choose>
   		             </td>
   		             <td>备注:</td>
   		           	 <td><input id="remark" class="inp_width_98p" name="remark" value="${materials.remark}" /></td>
   		           </tr>
   		            <tr>
   		             <td>是否开启批次:</td>
   		             <td>
			             <select id="remark2" name="remark2" class="inp_width_98p required" >
	                		<option></option>
		                 	<option value="Y">是</option>
		                 	<option value="N">否</option>
	                	</select>
	                	<c:if test="${not empty materials.remark2 }">
	                		<script type="text/javascript">
	                			$("#remark2").val('${materials.remark2}');
	                		</script>
	                	</c:if>
   		             </td>
   		           </tr>
                </table>               
         </div>
         <div class="formBar">
	        <ul>
		       <li><div class="button"><div class="buttonContent"><button type="button" class="print" onclick="CloseDialog()">关闭</button></div></div></li>
	        </ul>
        </div>    
    </div>
</form>
</body>
</html>
